//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package common;

import java.security.SecureRandom;
import java.util.Random;
import java.util.UUID;

public class RandomIdentifiers {
    private static final int RAND_POOL_SIZE = 64;
    private static byte[] randomPool = new byte[68];
    private static Random rGen;
    private static int rand_pool_pos;

    static {
        (new SecureRandom()).nextBytes(randomPool);
        int pool_seed = b2i(4, randomPool, 64);
        rGen = new Random((long)pool_seed);
    }

    public RandomIdentifiers() {
    }

    private static int b2i(int n, byte[] b, int offset) {
        switch(n) {
            case 2:
                return b[offset] << 8 | b[offset + 1];
            case 3:
                return b[offset] << 16 | b[offset + 1] << 8 | b[offset + 2];
            case 4:
                return b[offset] << 24 | b[offset + 1] << 16 | b[offset + 2] << 8 | b[offset + 3];
            default:
                return 0;
        }
    }

    private static byte[] getRandomBytes(int dstLen) {
        byte[] rb = new byte[dstLen];

        for(int i = 0; i < dstLen; ++i) {
            if(++rand_pool_pos < 0) {
                rand_pool_pos = 0;
            }

            int rval = rGen.nextInt() ^ randomPool[rand_pool_pos % 64];
            rb[i] = (byte)rval;
        }

        return rb;
    }

    public static byte[] getNextAndroidID() {
        return getRandomBytes(8);
    }

    public static String getNextAdvertisingID(byte[] seed) {
        return UUID.nameUUIDFromBytes(seed).toString();
    }

    public static byte[] getNextMACAddress() {
        byte[] rndb = getRandomBytes(3);
        byte[] mac = new byte[]{(byte)8, (byte)0, (byte)39, rndb[0], rndb[1], rndb[2]};
        return mac;
    }
}
